package com.longway.core.ext.excel.formats.model.emulate;

import java.util.HashMap;

import com.longway.core.ext.excel.data.RowsetData;
/**
 * @author ryc
 * 2015-4-22 上午10:29:32
 */
public class ExpressionEmulate
{
    private static ExpressionEmulate instance = new ExpressionEmulate();

    public static ExpressionEmulate getInstance()
    {
        return instance;
    }

    /**
     *
     * @param formula
     * @param value
     * @param dataValues
     * @return
     */
    public String emulate(String formula, String value, String type, RowsetData rowsetData)
    {
        TokenAnalysis parse = new TokenAnalysis(formula);
        int status = 0;           //0 是需要标识    1是需要运算符   2 是括号运算
        String token = null;
        String opt = "+";
        long longValueResult = 0;
        double doubleValueResult = 0;
        if (value != null)
        {
            if (type.equalsIgnoreCase("long"))
            {
                longValueResult += Long.valueOf(value);
            }
            else
            {
                doubleValueResult += Double.valueOf(value);
            }
        }

        while ((token = parse.getToken()) != null)
        {
        	
        }
        return String.valueOf(doubleValueResult);
    }

    private double calculate(double doubleValueResult, Double fieldValue, String opt)
    {
        if (opt == "+")
        {
            return doubleValueResult + fieldValue;
        }
        if (opt == "-")
        {
            return doubleValueResult - fieldValue;
        }
        if (opt == "*")
        {
            return doubleValueResult * fieldValue;
        }
        if (opt == "/")
        {
            return doubleValueResult / fieldValue;
        }
        return doubleValueResult;
    }

    private long calculate(long longValueResult, Long fieldValue, String opt)
    {
        if (opt == "+")
        {
            return longValueResult + fieldValue;
        }
        if (opt == "-")
        {
            return longValueResult - fieldValue;
        }
        if (opt == "*")
        {
            return longValueResult * fieldValue;
        }
        if (opt == "/")
        {
            return longValueResult / fieldValue;
        }
        return longValueResult;

    }
}
